#include <stdio.h>
#include "atmi.h"		/* TUXEDO  Header File */

main(int argc, char *argv[])
{

	char *sendbuf, *rcvbuf;
	long sendlen, rcvlen;
	int ret;
	FILE *fp_in, *fp_out;
	char in_file_name [1024*4];
	char out_file_name [1024*4];
	char svc_name [1024];
	char tgt_name [1024];
	int read_size;

	if (tpinit((TPINIT *) NULL) == -1) {
		(void) fprintf(stderr, "Tpinit failed[%s]\n", tpstrerror(tperrno));
		exit(1);
	}
	
	sendlen = 1024 * 4;

	/* Allocate STRING buffers for the request and the reply */

	if((sendbuf = (char *) tpalloc("CARRAY", NULL, sendlen+1)) == NULL) {
		(void) fprintf(stderr,"Error allocating send buffer\n");
		tpterm();
		exit(1);
	}

	if((rcvbuf = (char *) tpalloc("CARRAY", NULL, sendlen+1)) == NULL) {
		(void) fprintf(stderr,"Error allocating receive buffer\n");
		tpfree(sendbuf);
		tpterm();
		exit(1);
	}

	strcpy(sendbuf,"hello world");
	read_size = strlen( sendbuf);
  fprintf( stderr, ">%s(%d)<\n", sendbuf, read_size);

	/* ------------------------------------------------------------------ */
	ret = tpcall("SERVICE", (char *)sendbuf, read_size, (char **)&rcvbuf, &rcvlen, (long)0);
	if(ret == -1) {
		(void) fprintf(stderr, "Can't send request to service(%s)\n",tpstrerror(tperrno));
		tpfree(sendbuf);
		tpfree(rcvbuf);
		tpterm();
		exit(1);
	}

	(void) fprintf(stdout, ">%s<(%d)\n", rcvbuf, rcvlen);

	tpfree(sendbuf);
	tpfree(rcvbuf);
	tpterm();
	return(0);
}
